package com.yhsoft.bill.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yhsoft.bill.controller.request.*;
import com.yhsoft.bill.controller.response.SysYckLogOutVo;
import com.yhsoft.bill.controller.response.SysYszkMxOutVo;
import com.yhsoft.bill.controller.response.SysYszkOutVo;
import com.yhsoft.bill.entity.SysYszkMx;
import com.yhsoft.bill.service.ISysYszkMxService;
import com.yhsoft.bill.service.ISysYszkService;
import com.yhsoft.common.response.PageResult;
import com.yhsoft.common.vo.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 平台应收账款 前端控制器
 * </p>
 *
 * @author yyyyyyyh
 * @since 2023-11-03
 */
@Api(tags = {"H-财务统计-平台应收账款"})
@RestController
@RequestMapping("/bill/sysYszk")
public class SysYszkController {
    @Resource
    private ISysYszkService iSysYszkService;

    @Resource
    private ISysYszkMxService iSysYszkMxService;

    @ApiOperation("应收账款列表")
    @GetMapping("/getYszkList")
    public Result<PageResult<SysYszkOutVo>> getYszkList(SysYszkInVo inVo,
                                                        @RequestParam(value = "pageNo") Long pageNo,
                                                        @RequestParam(value = "pageSize") Long pageSize) {
        IPage<SysYszkOutVo> iPage = iSysYszkService.getYszkList(inVo, pageNo, pageSize);
        return Result.success(PageResult.valueOf(iPage));
    }

    @ApiOperation("应收账款详情")
    @GetMapping("/getYszkMx")
    public Result<PageResult<SysYszkMxOutVo>> getYszkMx(SysYszkMxInVo inVo,
                                                        @RequestParam(value = "companyId") Integer companyId,
                                                        @RequestParam(value = "pageNo") Long pageNo,
                                                        @RequestParam(value = "pageSize") Long pageSize) {
        IPage<SysYszkMxOutVo> iPage = iSysYszkMxService.getYszkMx(inVo, companyId, pageNo, pageSize);
        return Result.success(PageResult.valueOf(iPage));
    }

    @ApiOperation("收款")
    @PostMapping("/sk")
    public Result<?> sk(@RequestBody SysSkInVo inVo) {
        String result = iSysYszkMxService.sk(inVo);
        if(result.equals("success")){
            iSysYszkService.sk(inVo);
            return Result.success(result);
        }
        return Result.fail(result);
    }

    @ApiOperation("还款")
    @PostMapping("/hk")
    public Result<?> hk(@RequestBody SysHkInVo inVo) {
        String result = iSysYszkMxService.hk(inVo);
        if(result.equals("success")){
            SysYszkMx yszkMx = iSysYszkMxService.getById(inVo.getId());
            iSysYszkService.hk(inVo, yszkMx.getPayAmount());
            return Result.success(result);
        }
        return Result.fail(result);
    }

    @ApiOperation("预存款消耗日志")
    @GetMapping("/getYckLog")
    public Result<PageResult<SysYckLogOutVo>> getYckLog(SysYckLogInVo inVo,
                                                        @RequestParam(value = "companyId") Integer companyId,
                                                        @RequestParam(value = "pageNo") Long pageNo,
                                                        @RequestParam(value = "pageSize") Long pageSize) {
        IPage<SysYckLogOutVo> iPage = iSysYszkService.getYckLog(inVo, companyId, pageNo, pageSize);
        return Result.success(PageResult.valueOf(iPage));
    }
}
